package cn.edu.nju.software.cdiy.algorithm.performance;

import cn.edu.nju.software.cdiy.bean.Monitor;
import cn.edu.nju.software.cdiy.util.Constant;

public class MonitorEvaluator implements Evaluator<Monitor>{

	@Override
	public double getPerformance(Monitor t) {
		double score = 0;
		
		//屏幕尺寸得分
		int screenSize = t.getScreenSize().getKey();
		double screenSizeScore = getScreenSizeBase(screenSize)*Constant.MON_STD_SCREENSIZE;
		
		//屏幕对比度得分
		int screenRatio = t.getScreenRatio().getKey();
		double screenRatioScore = getScreenRatioBase(screenRatio)*Constant.MON_STD_SCREENRATIO;
		
		//屏幕分辨率得分
		int optimumResolution = t.getOptimumResolution().getKey();
		double optimumResolutionScore = getOptimumResolutionBase(optimumResolution)*Constant.MON_STD_OPTIMUMRESOLUTION;
		
		//亮度得分
		int brightness = t.getBrightness();
		double brightnessScore = getBrightnessBase(brightness)*Constant.MON_STD_BRIGHTNESS;
		
		//灰阶相应时间得分
		int grayResponseTime = t.getGrayResponseTime();
		double grayResponseTimeScore = getGrayResponseTimeBase(grayResponseTime)*Constant.MON_STD_GRAYRESPONSETIME;
		
		//颜色
		double displayColor = t.getDisplayColor();
		double displayColorScore = getDisplayColorBase(displayColor)*Constant.MON_STD_DISPLAYCOLOR;
		
		
		score = screenSizeScore+screenRatioScore+optimumResolutionScore+brightnessScore+grayResponseTimeScore+displayColorScore;
		return score;
	}

	private double getDisplayColorBase(double displayColor) {
		/*
		 * 颜色基础分
		 * 16.7			90
		 * 其他			70
		 * 
		 * */
		if(displayColor==16.7)
			return 90;
		else return 70;
	}

	private double getGrayResponseTimeBase(int grayResponseTime) {
		/*
		 * 灰阶相应时间基础分
		 * 2			90
		 * 5			80
		 * 6			70
		 * 8			60
		 * 8-			50
		 * */
		if(grayResponseTime==2)
			return 90;
		else if(grayResponseTime==5)
			return 80;
		else if(grayResponseTime==6)
			return 70;
		else if(grayResponseTime==8)
			return 60;
		else return 50;
	}

	private double getBrightnessBase(int brightness) {
		/*
		 * 亮度基础分
		 * -200			70
		 * 200-300		80
		 * 300-400		85
		 * 400-			90
		 * */
		if(brightness<=200)
			return 70;
		else if(brightness>200 && brightness<=300)
			return 80;
		else if(brightness>300 && brightness<=400)
			return 85;
		else return 90;
	}

	private double getOptimumResolutionBase(int optimumResolution) {
		/*
		 * 分辨率基础分
		 * 1031			80
		 * 1032			90
		 * 
		 * */
		if(optimumResolution==1031)
			return 80;
		else return 90;
	}

	private double getScreenRatioBase(int screenRatio) {
		/*
		 * 屏幕对比度基础分
		 * 858,859		80
		 * 
		 * 856,857		90
		 * 
		 * */
		if(screenRatio==858 ||screenRatio ==859)
			return 80;
		else return 90;
	}

	private double getScreenSizeBase(int screenSize) {
		/*
		 * 屏幕尺寸基础分
		 * 841				70
		 * 842-843			75
		 * 844-846			80
		 * 847-849			85
		 * 850-				90
		 * */
		if(screenSize==841)
			return 70;
		else if(screenSize==842 || screenSize==843)
			return 75;
		else if(screenSize==844 || screenSize==845 || screenSize==846)
			return 80;
		else if(screenSize==847 || screenSize==848 || screenSize==849)
			return 85;
		else if(screenSize==850)
			return 90;
		else return 95;
	}

	

}
